package com.seleniti.enpareja.android.ui.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.seleniti.enpareja.android.R;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Action;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Event;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Operation;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Presenter;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetViewPresenter;

public class SolveNoPasswordSetViewWidget extends EnParejaBaseView<Event, Operation, Action, Presenter> implements
		SolveNoPasswordSetView {

	private WebView webView1;
	private Button btnGoBack;

	public SolveNoPasswordSetViewWidget() {
		super(false);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRetainInstance(true);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		this.presenter = new SolveNoPasswordSetViewPresenter(this, eventbus, operationManager, actionController);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.solve_no_password_view, container, false);

		this.webView1 = (WebView) view.findViewById(R.id.webView1);
		this.btnGoBack = (Button) view.findViewById(R.id.btnGoBack);

		this.webView1.loadUrl("file:///android_asset/solve_no_password_set.html");
		WebSettings webSettings = webView1.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

//		webView1.addJavascriptInterface(new WebAppInterface(this), "Android");
		webView1.setWebViewClient(new WebViewClient());
		webView1.setWebChromeClient(new WebChromeClient());

		this.btnGoBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				presenter.onGoBack();
			}
		});

		return view;
	}


}
